package models

import (
	"doctor-srv/basic/config"
	"gorm.io/gorm"
	"time"
)

// 预约
type Reservation struct {
	gorm.Model
	PatientId       int        `json:"patient_id" gorm:"type:int;comment:'患者id'"`
	DoctorId        int        `json:"doctor_id" gorm:"type:int;comment:'医生id'"`
	ReservationSn   string     `json:"reservation_sn" gorm:"type:varchar(50);comment:'预约单号'"`
	ReservationTime *time.Time `json:"reservation_time" gorm:"type:datetime;comment:'预约时间'"`
	Status          int        `json:"status" gorm:"type:int;comment:'预约状态 1-未开始 2-已结束'"`
}

func (r *Reservation) TableName() string {
	return "reservation"
}

func (r *Reservation) AddReservation() error {
	return config.DB.Create(&r).Error
}

func (r *Reservation) GetReservation(id int) error {
	return config.DB.Model(&Reservation{}).Where("id = ?", id).Limit(1).Find(&r).Error
}
